<?php
class LinkSaveEditAction extends AdminAction
{
	public function __construct()
	{
		parent::__construct();
		$this->responseType = 'json';
	}
	
	protected function afterConstruct()
	{
		$this->parseDtds('link','edit');
	}
	
	public function execute()
	{
		$id = $this->context->post('id');
		
		$data = $this->getValidData();
		if($data['index_show']!=1)
		{
			$data['index_show']	= 0;
		}
		
		$linkService = new BaseDbService('link');
		
		if(is_numeric($id) && $id)
		{
			$linkService->update($id, $data);
			$this->code	= 200;
		}
		else
		{
			$id	= $linkService->add($data);
			if($id)
			{
				$this->code	= 200;
			}
			else
			{
				$this->code	= 400;
			}
		}
		
		$this->data['forward'] = C('LtUrl')->generate('Link', 'Index');
	}
}
